package com.rockcent.mall.lib.factory;

import com.rockcent.mall.lib.domain.Article;
import com.rockcent.mall.lib.domain.ArticleCategory;
import com.rockcent.mall.lib.domain.enumclass.ArticleCategoryType;
import com.rockcent.mall.lib.dto.ArticleCategoryDto;
import com.rockcent.mall.lib.dto.ArticleDto;

/**
 * Created by Antinomy on 16/8/24.
 */

public class ArticleFactory {

    public Article createArticle(ArticleDto dto) {
        Article article = new Article();

        updateFormDto(article, dto);

        return article;
    }

    public void updateFormDto(Article article, ArticleDto dto) {
        article.setName(dto.getName());
        article.setMallId(dto.getMallId());
        article.setCategoryId(dto.getCategoryId());
        article.setParentCategoryId(dto.getParentCategoryId());
        article.setKeyword(dto.getKeyword());
        article.setContent(dto.getContent());
        article.setDisplayOrderId(dto.getDisplayOrderId());
    }

    public ArticleCategory createCategory(ArticleCategoryDto dto, ArticleCategoryType type) {
        ArticleCategory category = new ArticleCategory();

        category.setName(dto.getName());
        category.setMallId(dto.getMallId());
        category.setParentId(dto.getParentId());
        category.setType(type);
        category.setDisplayOrderId(dto.getDisplayOrderId());

        return category;
    }
}
